<template>
<view>
<view class="top">
   <view class="top_top">
      账户剩余金额: {{withdraw}}元
   </view>
   <view class="top_sr">
      <text>￥</text>
      <input @input="money" type="digit" :value="mon" placeholder="输入提现金额"></input>
   </view>
</view>
<view class="zuixiao">提现金额不能小于{{withdraw_min}}元,每日最多可提现{{day_limit}}元</view>
<view class="bottom">
   <view class="money">提现方式</view>
   <view class="fangshi">
      <view @tap="xuanzheFun" data-git="a" v-if="wxshow" :class="xuanzhe == 1 ? 'fangshi_b' : 'fangshi_a'">
         <image src="/static/remao_shop/img/weixinmoney.png"></image>
         微信
         <view class="dui" v-if="xuanzhe == 1">
            <view class="dui-a">
            <image src="/static/remao_shop/img/dui.png"></image>
            </view>
         </view>
      </view>
      <view @tap="xuanzheFun" data-git="b" v-if="yeshow" :class="xuanzhe == 2 ? 'fangshi_b' : 'fangshi_a'">
         <image class="img" src="/static/remao_shop/img/balance.png"></image>
         余额
         <view class="dui" v-if="xuanzhe == 2">
            <view class="dui-a">
            <image src="/static/remao_shop/img/dui.png"></image>
            </view>
         </view>
      </view>
   </view>
</view>
<button class="ti" hover-class="none" @tap="Confirm">提交申请</button>
</view>
</template>

<script>
// hotmall/packageB/Cash/Cash.js
var app = getApp();
import api from "../../../api";

export default {
  data() {
    return {
      radio: '1',
      //支付方式 1支付宝 2微信
      uid: '',
      mon: '',
      withdraw: '0.00',
      txmoney: '',
      //提现金额 
      xuanzhe: 1,
      withdraw_min: '0.00',
      day_limit: '0.00',
      wxshow: false,
      yeshow: false
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    wx.getStorage({
      key: 'userId',
      success: res => {
        console.log(res);
        this.setData({
          uid: res.data
        });
        this.ruleList();
      }
    });
    this.setData({
      withdraw: options.withdraw
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  methods: {
    getList: function () {
      app.globalData.request({
        url: api.default.distribution_withdraw,
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          user_id: this.uid,
          txmoney: this.txmoney,
          pay_type: this.xuanzhe
        },
        method: 'POST',
        success: res => {
          console.log(res);
          this.setData({});

          if (res.status == 1) {
            wx.showToast({
              title: res.msg,
              icon: 'success'
            });
            setTimeout(function () {
              wx.navigateBack({
                delta: 1
              });
            }, 1500);
          } else {
            wx.showToast({
              title: res.msg,
              icon: 'none'
            });
            this.setData({
              mon: ''
            });
          }
        }
      });
    },
    //判断提现方式显示
    ruleList: function () {
      app.globalData.request({
        url: api.default.distribution_sales_rule,
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          user_id: this.uid
        },
        method: 'POST',
        success: res => {
          console.log(res.withdraw_mode);
          this.setData({});

          for (let i = 0; i < res.withdraw_mode.length; i++) {
            console.log(res.withdraw_mode[i]);
            this.setData({
              withdraw_min: res.withdraw_min,
              day_limit: res.day_limit
            });

            if (res.withdraw_mode[i] == 1) {
              this.setData({
                wxshow: true
              });
            }

            if (res.withdraw_mode[i] == 2) {
              this.setData({
                yeshow: true
              });
            }
          }
        }
      });
    },

    //获取姓名金额账户
    money(e) {
      console.log(e.detail.value);
      this.setData({
        txmoney: e.detail.value
      });
    },

    //点击提现按钮
    Confirm: function () {
      this.getList();
    },
    //点击更改选中项样式提现方式
    xuanzheFun: function (e) {
      console.log(e.currentTarget.dataset.git);

      if (e.currentTarget.dataset.git == 'a') {
        this.setData({
          xuanzhe: 1
        });
      } else if (e.currentTarget.dataset.git == 'b') {
        this.setData({
          xuanzhe: 2
        });
      }
    }
  }
};
</script>
<style>
@import "./Cash.css";
</style>